package com.lanou.weekend02.service.impl;

import com.lanou.weekend02.bean.Student;
import com.lanou.weekend02.mapper.StudentMapper;
import com.lanou.weekend02.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lizhongren1.
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentMapper studentMapper;

    @Override
    public Student findStudent() {

        Student stu = new Student();
        stu.setSname("李四");
        stu.setAge(19);
        stu.setAddress("dalian");

        return stu;
    }

    @Override
    public List<Student> findAllStudent() {


        return studentMapper.findAllStudents();
    }

    @Override
    public Student searchStuById(Integer id) {
        return studentMapper.findStudentById(id);
    }

    @Override
    public boolean insertNewStudent(Student stu) {

        if (stu.getSname() == null || stu.getAge() == null || stu.getAddress() == null) {
            return false;
        }

        int count = studentMapper.insertNewStu(stu);

        if (count > 0){
            return true;
        }

        return false;
    }
}
